** TABLE 9: POLICY SIMULATIONS OF ALTERNATIVE POLICIES: 
** The code below requires prior estimation of RPM coefficients and predictions from Table 3 (mixl51) 
** one could do so from file Table3_Estimate_RPM_and_CL.do

* generate typeprovider in sequences (self=1 , public =2 private =3 doctors=4)
replace typeprovider = typeprovider+1

* RUN RPM INSTRUMENTED - FINAL SPECIFICATION in do file: Step4_EstimateRPM_and_CL.do


* Summarise the unconditional probability of choice j

/*
egen pr_modern = total(PR51) if type1==1, by(idid)  /*modern*/
egen t_trad = total(PR51)    if type1==0, by(idid)
egen t_public = total(PR51)  if  alt2==1, by(idid)
egen t_priv = total(PR51)    if  alt3==1, by(idid)

*/

* collapse and return the unconditioanl frequencies 
preserve 
keep if d_==1 & e(sample)==1
tab typeprovider
bys female: tab typeprovider 
restore 

/*
* return the unconditioanl frequencies by income quartile
preserve 
keep if d_==1 & e(sample)==1
tab typeprovider
bys quartiles: tab typeprovider 
restore 
*/


* The status quo conditional probability is PR0
egen pr_ = total(PR0) if e(sample), by(idid)
egen pr_1 = total(PR0) if typeprovider==1 & e(sample), by(idid)
egen pr_2 = total(PR0) if typeprovider==2 & e(sample), by(idid)
egen pr_3 = total(PR0) if typeprovider==3 & e(sample), by(idid)
egen pr_4 = total(PR0) if typeprovider==4 & e(sample), by(idid)



* collapse returns the mean probability of going to a class type facility in the estimation sample
preserve 
collapse (count) d_ (mean) pr_1 pr_2 pr_3 pr_4 if e(sample), by(typeprovider)
list typeprovider d_ pr*
restore 


* The mean (conditional) probability of of demand for class facilities by income quartile
preserve 
collapse (count) d_ (mean) pr_1 pr_2 pr_3 pr_4 if e(sample), by(typeprovider quartiles)
display "THESE ARE THE CONDITIONAL PROBABILITY BY INCOME QUARTILE"
list typeprovider quartile d_ pr* if quartiles==1
list typeprovider quartile d_ pr* if quartiles==2
list typeprovider quartile d_ pr* if quartiles==3
list typeprovider quartile d_ pr* if quartiles==4
restore 

* save the data set to use later in CI simulation
save "tempdata_CImixedlogit_vs4.dta", replace

****************************************************
**POLICY SIMULATION 1: NATIONAL INSURANCE POLICY FOR PUBLIC FACILITIES - PRICE DECREASE BY 100% FOR EVERYONE GOING TO PUBLIC FACILITIES
** change the price to zero ONLY for public facilities (for everyone)
****************************************************
preserve
set seed 545415

 foreach v of varlist p_i1 p_i2 p_i3 p_i4 {
 replace `v'= 0 if typeprovider==2 //*Type: Public Facilities*//
 }


 mixlpred PR2, nrep(500)    

egen pr2_  = total(PR2) if e(sample), by(idid)
egen pr2_1 = total(PR2) if typeprovider==1 & e(sample), by(idid)
egen pr2_2 = total(PR2) if typeprovider==2 & e(sample), by(idid)
egen pr2_3 = total(PR2) if typeprovider==3 & e(sample), by(idid)
egen pr2_4 = total(PR2) if typeprovider==4 & e(sample), by(idid)

* collapse returns the mean probability of going to a type class of facility in the estimation sample
*collapse (count) d_ (mean) pr_1 pr_2 pr_3 pr_4 pr2_ pr2_1 pr2_2 pr2_3 pr2_4  if e(sample), by(typeprovider)
*list typeprovider d_ pr*

* BY GENDER: collapse returns the mean probability of going to a type class of facility in the estimation sample by gender
collapse (count) d_ (mean) pr_1 pr_2 pr_3 pr_4 pr2_ pr2_1 pr2_2 pr2_3 pr2_4  if e(sample), by(typeprovider)
list typeprovider d_  pr*

restore




****************************************************
**POLICY SIMULATION 2: NATIONAL INSURANCE POLICY FOR PRIVATE & PUBLIC FACILITIES - PRICE DECREASE BY 100% FOR EVERYONE GOING TO PRIVATE & PUBLIC FACILITIES
** change the price to zero  for private and public facilities (for everyone)
****************************************************
preserve
set seed 545415

 foreach v of varlist p_i1 p_i2 p_i3 p_i4 {
 replace `v'= 0 if typeprovider==2 //*Type: Public Facilities*//
 replace `v'= 0 if typeprovider==3 //*Type: Private Facilities*//

 }

 mixlpred PR2, nrep(500)    

egen pr2_  = total(PR2) if e(sample), by(idid)
egen pr2_1 = total(PR2) if typeprovider==1 & e(sample), by(idid)
egen pr2_2 = total(PR2) if typeprovider==2 & e(sample), by(idid)
egen pr2_3 = total(PR2) if typeprovider==3 & e(sample), by(idid)
egen pr2_4 = total(PR2) if typeprovider==4 & e(sample), by(idid)

* collapse returns the mean probability of going to a type class of facility in the estimation sample
*collapse (count) d_ (mean) pr_1 pr_2 pr_3 pr_4 pr2_ pr2_1 pr2_2 pr2_3 pr2_4  if e(sample), by(typeprovider)
*list typeprovider d_ pr*

* BY GENDER: collapse returns the mean probability of going to a type class of facility in the estimation sample by gender
collapse (count) d_ (mean) pr_1 pr_2 pr_3 pr_4 pr2_ pr2_1 pr2_2 pr2_3 pr2_4  if e(sample), by(typeprovider)
list typeprovider d_  pr*


restore


********************************************************************
** TABLE 9, PANELS B AND C: GENDER EFFECTS IN POLICY SIMULATIONS
*To have a gender effect you need to work from the prediction of the model with gender from Table5_Heterogeneity_bygender.do
********************************************************************
* run the model with gender heterogeneity in price (using the price*male and price*female, so that the coefficients are the average effects)

use "tempdata_mixedlogitboot_g.dta", clear
replace typeprovider = typeprovider+1

* The status quo conditional probability is PR0G
egen pr_  = total(PR0GE) if esample, by(idid)
egen pr_1 = total(PR0GE) if typeprovider==1 & esample, by(idid)
egen pr_2 = total(PR0GE) if typeprovider==2 & esample, by(idid)
egen pr_3 = total(PR0GE) if typeprovider==3 & esample, by(idid)
egen pr_4 = total(PR0GE) if typeprovider==4 & esample, by(idid)

* collapse returns the mean probability of going to a type class of facility in the estimation sample by gender
preserve 
gen femaleindic = female
collapse (count) d_  (mean) femaleindic (mean) pr_ pr_1 pr_2 pr_3 pr_4 if esample & female==0, by(typeprovider)
display "THESE ARE THE CONDITIONAL PROBABILITY BY GENDER: MALE"
list typeprovider d_  female* pr* if female==0
restore

preserve 
gen femaleindic = female
collapse (count) d_  (mean) femaleindic (mean) pr_1 pr_2 pr_3 pr_4 if esample & female==1, by(typeprovider)
display "THESE ARE THE CONDITIONAL PROBABILITY BY GENDER: FEMALE"
list typeprovider d_  female* pr* if female==1
restore

preserve 
gen femaleindic = female
collapse (count) d_  (mean) pr_1 pr_2 pr_3 pr_4 if e(sample), by(typeprovider female)
display "THESE ARE THE CONDITIONAL PROBABILITY BY GENDER"
list typeprovider d_  female* pr* 
restore


* ADULT SAMPLE ONLY: The status quo conditional probability is PR0GA
drop pr_ pr_1 pr_2 pr_3 pr_4

egen pr_  = total(PR0GA) if e(sample), by(idid)
egen pr_1 = total(PR0GA) if typeprovider==1 & e(sample), by(idid)
egen pr_2 = total(PR0GA) if typeprovider==2 & e(sample), by(idid)
egen pr_3 = total(PR0GA) if typeprovider==3 & e(sample), by(idid)
egen pr_4 = total(PR0GA) if typeprovider==4 & e(sample), by(idid)


preserve
keep if d_==1 & e(sample)==1
bys female: tab typeprovider 
restore



****************************************************
**POLICY SIMULATION 1 BY GENDER: NATIONAL INSURANCE POLICY FOR PUBLIC FACILITIES - PRICE DECREASE BY 100% FOR EVERYONE GOING TO PUBLIC FACILITIES
** change the price to zero ONLY for public facilities (for everyone)
********************************************************************

preserve
set seed 545415

 foreach v of varlist p_i1_male p_i2_male p_i3_male p_i4_male p_i1_fem p_i2_fem p_i3_fem p_i4_fem {
 replace `v'= 0 if typeprovider==2 //*Type: Public Facilities*//
 }


 mixlpred PR2G, nrep(500)    //*can add ,nrep(500)**//

egen pr2_  = total(PR2G) if esample, by(idid)
egen pr2_1 = total(PR2G) if typeprovider==1 & esample, by(idid)
egen pr2_2 = total(PR2G) if typeprovider==2 & esample, by(idid)
egen pr2_3 = total(PR2G) if typeprovider==3 & esample, by(idid)
egen pr2_4 = total(PR2G) if typeprovider==4 & esample, by(idid)

* collapse returns the mean probability of going to a type class of facility in the estimation sample
gen femaleindic = female

collapse (count) d_ (mean) pr_1 pr2_ pr2_1 pr2_2 pr2_3 pr2_4  if esample, by(typeprovider female)
list typeprovider d_ female pr*

  
restore





****************************************************
**POLICY SIMULATION 2 BY GENDER : NATIONAL INSURANCE POLICY FOR PRIVATE & PUBLIC FACILITIES - PRICE DECREASE BY 100% FOR EVERYONE GOING TO PRIVATE & PUBLIC FACILITIES
** change the price to zero  for private and public facilities (for everyone)
****************************************************
preserve
set seed 545415

 foreach v of varlist p_i1_male p_i2_male p_i3_male p_i4_male p_i1_fem p_i2_fem p_i3_fem p_i4_fem   {
 replace `v'= 0 if typeprovider==2 //*Type: Public Facilities*//
 replace `v'= 0 if typeprovider==3 //*Type: Private Facilities*//

 }


 mixlpred PR2G, nrep(500)    //*can add ,nrep(500)**//

egen pr2_  = total(PR2G) if e(sample), by(idid)
egen pr2_1 = total(PR2G) if typeprovider==1 & esample, by(idid)
egen pr2_2 = total(PR2G) if typeprovider==2 & esample, by(idid)
egen pr2_3 = total(PR2G) if typeprovider==3 & esample, by(idid)
egen pr2_4 = total(PR2G) if typeprovider==4 & esample, by(idid)

* collapse returns the mean probability of going to a type class of facility in the estimation sample
gen femaleindic = female


* BY GENDER: collapse returns the mean probability of going to a type class of facility in the estimation sample by gender
collapse (count) d_ (mean) pr_2 pr_3 pr2_ pr2_1 pr2_2 pr2_3 pr2_4  if esample, by(typeprovider female)
list typeprovider d_ female  pr*


restore



****************************************************
** REVISION: ENPOWERMENT POLICY SIMULATION : 
** change the bargaining power of low bargaining household to high 
****************************************************
/* you have run: 
mixlogit d_  dist_dw_hf_2 dist_22   nu_8d alt2-alt4 nu_8dsq if spouse==1 , group(choicesit) id(idid) cluster(hh_id09)  rand(doctor_tot  generator2009 beds p_  p_lowbargain p_female p_female_lowbargain ) from(b55g, copy)
*/
* collapse and return the unconditioanl frequencies 
preserve 
keep if d_==1 & e(sample)==1
tab typeprovider
bys agedifflarge: tab typeprovider if female
restore 



* The status quo conditional probability is PR0
egen pr_H = total(PR0) if agedifflarge==0 & e(sample), by(idid)
egen pr_L = total(PR0) if agedifflarge==1 & e(sample), by(idid)

egen pr_H1 = total(PR0) if typeprovider==1 & agedifflarge==0 & e(sample), by(idid)
egen pr_L1 = total(PR0) if typeprovider==1 & agedifflarge==1 & e(sample), by(idid)

egen pr_H2 = total(PR0) if typeprovider==2 & agedifflarge==0 & e(sample), by(idid)
egen pr_L2 = total(PR0) if typeprovider==2 & agedifflarge==1 & e(sample), by(idid)

egen pr_H3 = total(PR0) if typeprovider==3 & agedifflarge==0 & e(sample), by(idid)
egen pr_L3 = total(PR0) if typeprovider==3 & agedifflarge==1 & e(sample), by(idid)

egen pr_H4 = total(PR0) if typeprovider==4 & agedifflarge==0 & e(sample), by(idid)
egen pr_L4 = total(PR0) if typeprovider==4 & agedifflarge==1 & e(sample), by(idid)



* collapse returns the mean probability of going to a class type facility in the estimation sample
preserve 
collapse (count) d_ (mean) pr_H pr_L pr_H1 pr_L1 pr_H2 pr_L2 pr_H3 pr_L3 pr_H4 pr_L4 if e(sample) & female==1, by(typeprovider)
list typeprovider d_ pr*
restore 


* Policy Simulations 

preserve
set seed 545415

 foreach v of varlist p_lowbargain p_female_lowbargain {
 replace `v'= 0 if female==1 & agedifflarge==1 //*moving females to high bargaining status*//
 }


 mixlpred PR2, nrep(500)    

 capture drop pr_H pr_L pr_H1 pr_L1 pr_H2 pr_L2 pr_H3 pr_L3 pr_H4 pr_L4
egen pr_H = total(PR2) if agedifflarge==0 & e(sample), by(idid)
egen pr_L = total(PR2) if agedifflarge==1 & e(sample), by(idid)

egen pr_H1 = total(PR2) if typeprovider==1 & agedifflarge==0 & e(sample), by(idid)
egen pr_L1 = total(PR2) if typeprovider==1 & agedifflarge==1 & e(sample), by(idid)

egen pr_H2 = total(PR2) if typeprovider==2 & agedifflarge==0 & e(sample), by(idid)
egen pr_L2 = total(PR2) if typeprovider==2 & agedifflarge==1 & e(sample), by(idid)

egen pr_H3 = total(PR2) if typeprovider==3 & agedifflarge==0 & e(sample), by(idid)
egen pr_L3 = total(PR2) if typeprovider==3 & agedifflarge==1 & e(sample), by(idid)

egen pr_H4 = total(PR2) if typeprovider==4 & agedifflarge==0 & e(sample), by(idid)
egen pr_L4 = total(PR2) if typeprovider==4 & agedifflarge==1 & e(sample), by(idid)

*collapse returns the mean probability of going to a type class of facility in the estimation sample
collapse (count) d_ (mean) pr_H pr_L pr_H1 pr_L1 pr_H2 pr_L2 pr_H3 pr_L3 pr_H4 pr_L4 if e(sample) & female==1, by(typeprovider)
list typeprovider d_ pr*

/*
*By GENDER: collapse returns the mean probability of going to a type class of facility in the estimation sample
gen femaleindic = female

collapse (count) d_ (mean) pr_1 pr2_ pr2_1 pr2_2 pr2_3 pr2_4  if esample, by(typeprovider female)
list typeprovider d_ female pr*
*/

restore



